﻿using Styx;
using Styx.WoWInternals;

using WuzzCollection.Helpers;

namespace WuzzCollection.Classes
{
    internal partial class Monk : AbstractClass
    {
        public override void ApproachAndFaceTarget()
        {
            if (!Me.CurrentTarget.IsWithinMeleeRange)
            {
                Styx.Pathing.Navigator.MoveTo(Me.CurrentTarget.Location);

                if (BotSettings.BotMovement && Me.CurrentTarget.Distance > 15)
                {
                    Spell.CastSpecial("Roll");
                }
            }
            
            if (Me.CurrentTarget.IsWithinMeleeRange)
            {
                WoWMovement.MoveStop();
                WoWMovement.ConstantFace(Me.CurrentTarget.Guid);
            }
        }

        public override bool NeedPreCombatBuffs()
        {
            if (Spell.HasSpell("Legacy of the Emperor") && !Unit.HasAnyAura(Me, Lists.Buffs.StatBuffs))
            {
                return true;
            }
            if (Spell.HasSpell("Legacy of the White Tiger") && !Unit.HasAnyAura(Me, Lists.Buffs.CritBuffs))
            {
                return true;
            }
            return false;
        }

        public override void PreCombatBuffs()
        {
            if (!Unit.HasAnyAura(Me, Lists.Buffs.StatBuffs))
            {
                if (Spell.CastBuff("Legacy of the Emperor", Me)) { return; }
            }

            if (!Unit.HasAnyAura(Me, Lists.Buffs.CritBuffs))
            {
                if (Spell.CastBuff("Legacy of the White Tiger", Me)) { return; }
            }
        }

        public override bool CastHeal()
        {
            // Chi Wave
            if (Me.HealthPercent <= 75 && Me.CurrentChi >= 3 && Me.CurrentTarget.IsWithinMeleeRange)
            {
                if (Spell.CastHeal("Chi Wave")) { return true; }
            }
            // Expel Harm
            if (Me.HealthPercent < 50 && Me.CurrentEnergy >= 40)
            {
                if (Spell.CastHeal("Expel Harm")) { return true; }
            }

            return false;
        }

        public override bool CastDefensiveSpells()
        {
            // Fortifying Brew if under 75% HP
            if (Me.HealthPercent < 75)
                if (Spell.CastBuff("Fortifying Brew")) { return true; }

            // Touch of Karma if possible. HP under 75%
            if (Me.HealthPercent <= 50 && Me.CurrentTarget.IsWithinMeleeRange)
                if (Spell.CastSpecial("Touch of Karma")) { return true; }

            return false;
        }

        public override bool CastInterrupt()
        {
            if (Me.CurrentTarget.IsCasting && Me.CurrentTarget.CanInterruptCurrentSpellCast)
            {
                if (Me.CurrentTarget.IsWithinMeleeRange)
                {
                    if (Spell.CastSpecial("Spear Hand Strike")) { return true; }
                }
            }
            return false;
        }

        public override void Pull()
        {
            AutoAttack();

            if (BotSettings.BotTaunt && Me.CurrentTarget.Distance < 40)
            {
                Me.Face();
                Spell.CastSpecial("Provoke");
            }

            ApproachAndFaceTarget();
        }

        public override void AutoAttack()
        {
            if (!Me.IsAutoAttacking)
            {
                Me.ToggleAttack();
            }
        }

        public override void RunRotation()
        {
            if (Me.Level < 10)
            {
                LowbieRotation();
            }
            else
            {
                switch (Me.Specialization)
                {
                    case WoWSpec.MonkWindwalker:
                        WindwalkerRotation();
                        break;
                    default:
                        LowbieRotation();
                        break;
                }
            }
        }
    }
}